package owlapps2012.klpfc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ASConnection {

	 public static Connection getSimpleConnection() {
		    String DB_CONN_STRING = "jdbc:as400://10.10.0.90;sort=table;sort table=QGPL.SPIN_SORT;datatruncation=false;errors=full;date format=iso;time format=hms;";
		    String DRIVER_CLASS_NAME = "com.ibm.as400.access.AS400JDBCDriver";
		    String USER_NAME = "PNOWARA";
		    String PASSWORD = "nowarap";
		    
		    Connection result = null;
		    try {
		       Class.forName(DRIVER_CLASS_NAME).newInstance();
		    }
		    catch (Exception e){
		       System.out.println("Check classpath. Cannot load db driver: " + DRIVER_CLASS_NAME);
		       e.printStackTrace();
		    }

		    try {
		      result = DriverManager.getConnection(DB_CONN_STRING, USER_NAME, PASSWORD);
		    }
		    catch (SQLException e){
		    	System.out.println( "Driver loaded, but cannot connect to db: " + DB_CONN_STRING);
			       e.printStackTrace();

		    }
		    return result;
		  }
	 
	 public static Connection getSimpleConnection(String user, String pass) 
	 {
		    String DB_CONN_STRING = "jdbc:as400://10.10.0.90;sort=table;sort table=QGPL.SPIN_SORT;datatruncation=false;errors=full;date format=iso;time format=hms;";
		    String DRIVER_CLASS_NAME = "com.ibm.as400.access.AS400JDBCDriver";
		    
		    Connection result = null;
		    try {
		       Class.forName(DRIVER_CLASS_NAME).newInstance();
		    }
		    catch (Exception e){
		       System.out.println("Check classpath. Cannot load db driver: " + DRIVER_CLASS_NAME);
		       e.printStackTrace();
		    }

		    try {
		      result = DriverManager.getConnection(DB_CONN_STRING, user, pass);
		    }
		    catch (SQLException e){
		    	System.out.println( "Driver loaded, but cannot connect to db: " + DB_CONN_STRING);
			       e.printStackTrace();

		    }
		    return result;
		  }
}
